package com.ssm.sfzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.sfzy.entity.Article;
import com.ssm.sfzy.entity.Company;
import com.ssm.sfzy.mapper.CompanyMapper;
import com.ssm.sfzy.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName CompanyServiceImpl
 * @Description TODO
 * @Author Happy
 * @Date 2024年03月30日 11:46
 * @Version 1.0
 */
@Service
public class CompanyServiceImpl implements CompanyService {
    @Autowired
    private CompanyMapper companyMapper;

    @Override
    public void add(Company entity) {
        companyMapper.insert(entity);
    }

    @Override
    public void edit(Company entity) {
companyMapper.update(entity);
    }

    @Override
    public void remove(Integer id) {
companyMapper.delete(id);
    }

    @Override
    public void removeBatch(Integer[] ids) {
companyMapper.deleteBatch(ids);
    }

    @Override
    public List<Company> find(Company entity) {
        return companyMapper.select(entity);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, Company entity) {
        //
        PageHelper.startPage(pageNum,pageSize);
        List<Company> list = companyMapper.select(entity);
        //
        PageInfo<Company> pageInfo=new PageInfo<>(list);
        //整合处理
        Map<String,Object> map = new HashMap<>();
        map.put("list",pageInfo.getList());
        map.put("total",pageInfo.getTotal());
        return map;
    }

    @Override
    public Company findById(Integer id) {
        return companyMapper.selectById(id);
    }
}
